﻿//打开字滑入效果
window.onload = function(){
	$(".connect p").eq(0).animate({"left":"0%"}, 600);
	$(".connect p").eq(1).animate({"left":"0%"}, 400);
};


//jquery.validate表单验证
$(document).ready(function(){

	//登陆表单验证
	loginValidate = function(){
		$("#loginForm").validate({
			rules:{
				username:{
					required:true,//必填
					minlength:3, //最少3个字符
					maxlength:20,//最多20个字符
				},
				password:{
					required:true,
					minlength:3, 
					maxlength:20,
				},
			},
			//错误信息提示
			messages:{
				username:{
					required:"必须填写用户名",
					minlength:"用户名至少为3个字符",
					maxlength:"用户名至多为20个字符",
					remote: "用户名已存在",
				},
				password:{
					required:"必须填写密码",
					minlength:"密码至少为3个字符",
					maxlength:"密码至多为20个字符",
				},
			},

		});
	}

	/**
	 * AJAX方式表单提交()
	 */
	function ajaxSubmitFrom(){
		$('#submit').click(function () {
			var from = $('.ajaxSubmitFrom');
			action = from.attr('action');
			method = from.attr('method');
			data   = from.serialize();

		    $.ajax({
		        url: action,
		        type: method,
		        data: data,
		        success: function (info) {
		            if (info.code === 1) {
		                setTimeout(function () {
		                    location.href = info.url;
		                }, 1000);
		            }
		            layer.msg(info.msg);
		        }
		    });

		    return false;
		});
	}



	//登陆表单验证
	loginValidate();

	// ajax的方式提交表单
	ajaxSubmitFrom();
});
